package demon;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 21626
 * Date: 2024-10-23
 * Time: 11:18
 */
public class Game {
    public static final String[] SUITS = {"♥","♠","♣","♦"};

    public List<Card> CreatCards(){
        List<Card> cardList = new ArrayList<>();
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(SUITS[i],j );
                cardList.add(card);
            }
        }
        return cardList;
    }
    public void shufflr(List<Card> cardList){
        Random random = new Random();
        for (int i = cardList.size() - 1;  i > 0; i--) {
            int radomIndex = random.nextInt(i);
            Swap(cardList,i,radomIndex);
        }
    }
    public void Swap(List<Card> cardList,int i,int j){
        Card tmp = cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmp);
    }
    public List<List<Card>> play(List<Card> cardList){
        List<List<Card>> hand = new ArrayList<>();

        List<Card> hand0 = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();

        hand.add(hand0);
        hand.add(hand1);
        hand.add(hand2);
        //每个人总共五张牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                //每次 每人 揭一张
                Card card = cardList.remove(0);//接收cardList删除的元素
                hand.get(j).add(card);
            }
        }
        return hand;
    }
}
